package cn.iocoder.mall.user.biz.dao;

import cn.iocoder.mall.user.api.entities.SellerVo;
import cn.iocoder.mall.user.biz.dataobject.Seller;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description: 商户/店员
 * @Author: jeecg-boot
 * @Date:   2019-10-23
 * @Version: V1.0
 */
@Mapper
public interface SellerMapper extends BaseMapper<Seller> {
    /**
     * 商户/店员通过手机号查询
     * @param mobile
     * @return
     */
    @Select("select * from seller where mobile = #{mobile}")
    Seller getByMobile(@Param("mobile") String mobile);

    /**
     * 商户/店员通过用户名查询
     * @param username
     * @return
     */
    @Select("select * from seller where username = #{username}")
    Seller getByUserName(@Param("username") String username);
    /**
     * 查询该用户是否已添加过
     * @param mobile
     * @return
     */
    @Select("select * from seller where mobile = #{mobile}" )
    Seller getUser(@Param("mobile") String mobile);
    /**
     * 删除用户后，二次添加
     * @param id
     */
    @Update("update seller set is_delete = 0 where id = #{id}")
    void recoverOneUser(@Param("id") String id);
    /**
     * 商户删除一个店员
     * @param id
     */
    @Update("update seller set is_delete = 1 where id = #{id}")
    void deleteById(@Param("id") String id);
    /**
     * 商户批量删除店员
     * @param asList
     */
    void deleteByIdS(@Param("asList") List<String> asList);
    @Insert("insert into seller_clerk_relationship (mall_id, clerk_id, create_time) values (#{id}, #{clerkId}, #{creatTime})")
    /**
     * 新增一个店主与店员的关系
     * @param id
     * @param clerkId
     * @param creatTime
     * @return
     */
    boolean insertOneClerkRelationShip(@Param("id") String id, @Param("clerkId") String clerkId, @Param("creatTime") String creatTime);
    @Delete("delete from seller_clerk_relationship where mall_id=#{sellerId} and clerk_id=#{clerkId}")
    /**
     * 商户删除与店员的关系
     * @param sellerId
     * @param clerkId
     */
    void deleteSellerClerk(@Param("sellerId") String sellerId, @Param("clerkId") String clerkId);
    /**
     * 商户批量删除与店员的关系
     * @param sellerId
     * @param clerkIds
     */
    void deleteSellerClerks(@Param("sellerId") String sellerId, @Param("clerkIds") List<String> clerkIds);

    /**
     * 获取该商户下的店员列表
     * @param userId
     * @return
     */
    List<SellerVo> getListOfClerk(String userId);



    @Update("update seller set is_delete = 1 where id = #{id}")
    void deleteSeller(@Param("id") String id);
    /**
     * 通过id批量删除商户
     * @param asList
     */
    void deleteSellers(@Param("asList") List<String> asList);

    @Select("select mobile from seller where id = #{id}")
    String getMobileById(@Param("id") String receiver);
}
